package security.Authentication.StaticData;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import security.Authorization.Base.AuthorizationLevel;

/**
 * Have static information about users with their password
 * @author Andreas Carmvall
 */
public class StaticUserPassInfo {

	/**
	 * The static information about the users
	 */
    private static final Map<String, UserData> users;
    
    /**
     *  Make a static initialization of the map
     */
    static {
        Map<String, UserData> temp = new HashMap<String, UserData>();
        temp.put("TestUser", new UserData("Abc123!", AuthorizationLevel.USER, "user@email.com"));
        temp.put("QwertyUser", new UserData("Qwerty1.", AuthorizationLevel.ADMIN, "admin@email.com"));
        users = Collections.unmodifiableMap(temp);
    }
	
    /**
     * Check if the user with the passed parameters exists in the
     * static information
     * @param userName the user name
     * @param password the password
     * @return the authorization level of the user
     */
	public static AuthorizationLevel checkUser(String userName, String password) {
		if (users.containsKey(userName)) {
			UserData user = users.get(userName);
			
			if (user.getPassword().equals(password)) {
				return user.getLevel();
			}
		}
		
		return AuthorizationLevel.NONE;
	}
	
	/**
	 * Get the email to a user
	 * @param userName the user name
	 * @return the user email
	 */
	public static String getUserEmail(String userName) {
		if (users.containsKey(userName)) {
			UserData user = users.get(userName);
			
			return user.getEmail();
		}
		
		return null;
	}
}
